import grails.test.*

class CityTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testCityCreation() {
        City existingCity = new City(name:"shanghai")
        mockForConstraintsTests(City, [existingCity])

        City city = new City()
        assertFalse city.validate()
        assertEquals "nullable", city.errors["name"]

        city.name=" "
        assertFalse city.validate()
        assertEquals "blank", city.errors["name"]

        city.name='shanghai'
        assertFalse city.validate()
        assertEquals 'unique', city.errors['name']

        city.name="longerthan50_12345678901234567890123456789012345678"
        assertFalse city.validate()
        assertEquals 'maxSize', city.errors["name"]

        city.name="longerthan50_1234567890123456789012345678901234567"
        assertTrue city.validate()
}
}
